<template>

  <div>
     <van-nav-bar
  title="账号登录"

  left-arrow
  @click-left="$router.back()"

/>
    <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"

    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写用户名' },
    {pattern:/^\w{5,}/, message:'用户名至少5位哦'}]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"

    placeholder="请输入密码"
    :rules="[{ required: true, message: '请填写密码' },
    {pattern:/^\w{6,}/, message:'密码至少6位哦'}]"
  />
  <div style="margin: 16px;">
    <van-button square color="#1cb676" type="primary" size="large" native-type="submit">登录</van-button>
  </div>
</van-form>
<!-- <router-link></router-link> -->
  </div>
</template>

<script>
import { setToken } from '@/utils/storage'
import { login } from '@/api/user'
export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (value) {
      // console.log(value)
      const { body } = await login(value)
      console.log(body)
      setToken(body.token)
      this.$toast.success('登录成功')
      this.$router.push('/my')
    }
  }
}
</script>

<style>
.te{
  width:100%;
  height: 50px;
  background-color: #fff;
  padding: auto;
}
.link{
  color:#666666;
  text-align: center;
 line-height: 50px;
  font-size: 18px;

}
</style>
